enum MODELIST {
    //% block="被动查询"
    PASSIVE,
    //% block="主动输出"
    ACTIVE
}
enum PMSLIST {
    //% block="PM1.0 浓度（CF=1，标准颗粒物）µg/𝑚3"
    1,
    //% block="PM2.5 浓度（CF=1，标准颗粒物）µg/𝑚3"
    2,
    //% block="PM10 浓度（CF=1，标准颗粒物）µg/𝑚3"
    3,
    //% block="PM1.0 浓度（大气环境下）µg/𝑚3"
    4,
    //% block="PM2.5 浓度（大气环境下）µg/𝑚3"
    5,
    //% block="PM10 浓度（大气环境下）µg/𝑚3"
    6,   
    //% block="0.1 升空气中直径在 0.3um 以上颗粒物个数"
    7,
    //% block="0.1 升空气中直径在 0.5um 以上颗粒物个数"
    8,
    //% block="0.1 升空气中直径在 1.0um 以上颗粒物个数"
    9,
    //% block="0.1 升空气中直径在 2.5um 以上颗粒物个数"
    10,
    //% block="0.1 升空气中直径在 5.0um 以上颗粒物个数"
    11,
    //% block="0.1 升空气中直径在 10um 以上颗粒物个数"
    12
}


//% color="#5ba55b" iconWidth=50 iconHeight=40
namespace PMS9103M { 

    //% block="PMS9103M 数字式通用颗粒物传感器 接收(R)管脚#[RXPIN] 发射(T)管脚#[TXPIN] 初始化[MODE]" blockType="command"
    //% RXPIN.shadow="dropdown" RXPIN.options="PIN_DigitalWrite" 
    //% TXPIN.shadow="dropdown" TXPIN.options="PIN_DigitalWrite"
    //% MODE.shadow="dropdown" MODE.options="MODELIST" 
    export function PMS9103M_INIT(parameter: any, block: any) {
        let rxpin = parameter.RXPIN.code;
        let txpin = parameter.TXPIN.code;
        let mode = parameter.MODE.code;
        Generator.addInclude('include_RL_PMS9103M_h', '#include "RL_PMS9103M.h"');
        Generator.addObject(`PMS9103M_pms_${rxpin}${txpin}`, `PMS9103M`,  `pms(${rxpin},${txpin});`);
        Generator.addSetup(`pms_begin`, `pms.begin(9600);`);
        Generator.addSetup(`pms_setMode`,`pms.setMode(${mode});`);
    }   
    //% block="PMS9103M 数字式通用颗粒物传感器 请求数据" blockType="command"
    export function PMS9103M_REQUEST(parameter: any, block: any) {
       Generator.addCode(`pms.request();`);
    }  
    //% block="PMS9103M 数字式通用颗粒物传感器 有数据可读？" blockType="boolean"
    export function PMS9103M_READPMS(parameter: any, block: any) {
       Generator.addCode(`pms.readPms()`);
    }  
    //% block="PMS9103M 数字式通用颗粒物传感器 读取[PMS]" blockType="reporter"
    //% PMS.shadow="dropdown" PMS.options="PMSLIST" 
    export function PMS9103M_GETDATA(parameter: any, block: any) {
        let pms= parameter.PMS.code;
        Generator.addCode(`pms.getData(${pms})`);
    }   


}
